package cn.echo.modules.sys.service;


import cn.echo.modules.sys.dao.SysAdminMapper;
import cn.echo.modules.sys.entity.Article;
import cn.echo.modules.sys.entity.SysAdmin;
import cn.echo.modules.sys.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/4/9.
 */
@Service//让service成为组件(对象) 可以装配(注入)
public class SysAdminService {
    /* @Autowired
   private SqlSession session;*/
    @Autowired
    private SysAdminMapper sysAdminMapper;//注入mapper对象
    public List<SysAdmin> findAll(SysAdmin admin) {
//        SqlSession session = null;
//        session = MyBatisUtils.getSqlFactory().openSession();
//        SysAdminMapper siteDao = session.getMapper(SysAdminMapper.class);
        List<SysAdmin> siteList = sysAdminMapper.findAll(new SysAdmin());
     //   session.close();
        return siteList;
    }
    public SysAdmin findById(String id) {
//        SqlSession session = null;
//        session = MyBatisUtils.getSqlFactory().openSession(true);
//        SysAdminMapper sysAdminMapper = session.getMapper(SysAdminMapper.class);
        SysAdmin sysAdmin = null;
        List<SysAdmin> articleList = null;
        try {
            sysAdmin= sysAdminMapper.findById(id);


        } catch (Exception e) {
            System.out.println("查询失败");
            e.printStackTrace();
        } finally {
//            if (session!=null){
//               // session.close();
//            }
        }
        return sysAdmin;
    }
}
